//
//  KSSubmitRefundTableViewCell.swift
//  Supermarket
//
//  Created by liuxm on 2017/9/29.
//  Copyright © 2017年 kushao. All rights reserved.
//

import UIKit

protocol TextFieldDelegate: NSObjectProtocol {
    func textfieldcallBack(num: String,money: String,cellSection: NSInteger)
}

class KSSubmitRefundTableViewCell: UITableViewCell,UITextFieldDelegate {

    @IBOutlet weak var numTf: UITextField!
    @IBOutlet weak var moneyTf: UITextField!
    
    @IBOutlet weak var goodsImage: UIImageView!
    @IBOutlet weak var goodsName: UILabel!
    @IBOutlet weak var introLabel: UILabel!
    weak var delegate: TextFieldDelegate?
    private var numString: String = ""
    private var moneyString: String = "0"
    private var numMax: Int = 0
    private var monenyMax: Float = 0.0
    private var cellSection = 0
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    func setDataWithModel(model: KSRefunListDataListGoodsModel,section: NSInteger) {
        self.cellSection = section
        numMax = model.refund_num
        monenyMax = Float(numMax) * model.selling_price
        goodsImage.sd_setImage(with: URL.init(string: model.goods_image), placeholderImage: UIImage.init(named: "Common_GoodsPlace"))
        goodsName.text = model.goods_name
    }
    
    @IBAction func textfieldChange(_ textField: UITextField) {
        if textField.isEqual(numTf) {
            numString = textField.text!
        } else {
            moneyString = textField.text!
            if Float(moneyString)! > monenyMax {
                print("大于")
            }
        }
        self.delegate?.textfieldcallBack(num: numString, money: moneyString,cellSection: cellSection)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.numTf.resignFirstResponder()
        self.moneyTf.resignFirstResponder()
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
